package main

import (
	"bytes"
	"compress/gzip"
	"encoding/binary"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"
)

const (
	indexUrl  string = "https://app.gushiwen.org/api/shiwen/ajaxshiwencont.aspx"
	userAgent string = "Dalvik/2.1.0 (Linux; U; Android 7.1.1; MI MAX 2 MIUI/V10.1.1.0.NDDCNFI)"
)

type Page struct {
}

func ungzip(body []byte) []byte {
	b := new(bytes.Buffer)
	binary.Write(b, binary.LittleEndian, body)
	r, _ := gzip.NewReader(b)

	defer r.Close()

	plainBody, _ := ioutil.ReadAll(r)
	return plainBody
}

func main() {
	fmt.Println("Hello")
	// id=0&page=1&pwd=&token=gswapi

	client := &http.Client{}
	req, _ := http.NewRequest("POST", indexUrl, nil)
	req.Header.Set("User-Agent", userAgent)
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
	req.Header.Set("Host", "app.gushiwen.org")
	//req.Header.Set("Accept-Encoding", "gzip")
	//req.Header.Set("Connection", "Keep-Alive")

	form := url.Values{
		"id":    {"0"},
		"page":  {"1"},
		"pwd":   {""},
		"token": {"gswapi"},
	}
	req.Body = ioutil.NopCloser(strings.NewReader(form.Encode()))

	res, _ := client.Do(req)
	body, _ := ioutil.ReadAll(res.Body)
	fmt.Println(string(body))

	page := &Page{}
	json.Unmarshal(body, page)
	fmt.Println(*page)

}
